import java.awt.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Menu {

    public static void main(String[] args) {
        new Menu().home();
    }

    /** 菜单文本 */
    private static final String MENU_TEXT = "" +
            "1. 添加出行订单\r\n" +
            "2. 查看我的出行订单\r\n" +
            "3. 修改订单信息\r\n" +
            "4. 删除出行人\r\n";


    public static final Scanner INPUT = new Scanner(System.in);

    /**
     * 主菜单
     */
    public void home() {
        while (true) {
            // 打印菜单内容
            System.out.println(MENU_TEXT);
            System.out.print("请选择(1~6): ");

            switch (INPUT.next()) {
                case "1":
                    this.addOrderMenu();
                    break;
                case "2":
            }

        }
    }

    /**
     * 添加出行订单
     */
    public void addOrderMenu() {
        System.out.print("请输入出行日期: ");
        String time = INPUT.next();
        System.out.print("请输入联系人手机号码: ");
        String phone = INPUT.next();

        ArrayList<Person> personList = new ArrayList<>();
        double totalPrice = 0;

        System.out.println("***** 添加出行人信息 *****");
        while (true) {
            System.out.print("请选择类别(1成人,2儿童,3老人) 默认按成人算: ");
            int typeId = Menu.INPUT.hasNextInt() ? Menu.INPUT.nextInt() : 0;
            PersonType personType = PersonType.valueOf(typeId);

            Person info = personType.getInputPersonInfo().input();
            if (info == null) {
                System.out.println("输入信息有误，请重新输入！");
                continue;
            }
            personList.add(info);
            totalPrice += info.getPrice();

            System.out.println(personType.getPrintPersonInfo().generate(info));

            System.out.print("是否继续(Y/N): ");
            if (!Menu.INPUT.next().equals("y")) break;
        }

        Data.addOrder(phone, time, personList);
        System.out.printf("***** 订单信息 *****\r\n" +
                "出行日期：%s\r\n" +
                "联系人手机号码：%s\r\n" +
                "订单总金额：%f元\r\n", time, phone, totalPrice);
    }
}
